package com.blb.community.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.community.Annotation.Log;
import com.blb.community.entity.ZyCommunity;
import com.blb.community.entity.ZyVisitor;
import com.blb.community.entity.vo.VisitorVo;
import com.blb.community.service.IZyCommunityService;
import com.blb.community.service.IZyVisitorService;
import com.blb.community.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 访客邀请  前端控制器
 * </p>
 *
 * @author 帅帅
 * @since 2022-07-02
 */
@Api(tags = "访客邀请模块")
@RestController
@RequestMapping("/zy-visitor")
public class ZyVisitorController {

    @Autowired
    private IZyVisitorService visitorService;

    @Autowired
    private IZyCommunityService communityService;

    @ApiOperation("分页+模糊查询")
    @GetMapping("/visitors/page")
    public ResponseResult<IPage<ZyVisitor>> getDictTypeAll(VisitorVo visitorVo) {
        IPage<ZyVisitor> zyVisitorIPage = visitorService.selectVisitorPage(new Page<>(visitorVo.getCurrent(), 5L), visitorVo);
        return ResponseResult.ok(zyVisitorIPage);
    }

    @ApiOperation("获取社区信息")
    @GetMapping("/communitys")
    public ResponseResult<List<ZyCommunity>> selectCommunitys() {
        List<ZyCommunity> list = communityService.list();
        return ResponseResult.ok(list);
    }

    @ApiOperation("分页+模糊查询不同小区访客列表")
    @GetMapping("/visitors/visitor")
    public ResponseResult<IPage<ZyVisitor>> selectVisitorVo(VisitorVo visitorVo) {
        IPage<ZyVisitor> zyVisitorIPage = visitorService.selectVisitorPage(new Page<>(visitorVo.getCurrent(), 5L), visitorVo);
        return ResponseResult.ok(zyVisitorIPage);
    }

    @Log(module = "修改访客信息", operationType = 2, requestMethod = "PUT")
    @ApiOperation("修改访客信息")
    @PutMapping("/visitor")
    public ResponseResult<String> updateBuilding(@RequestBody ZyVisitor visitor) {
        visitorService.updateById(visitor);
        return ResponseResult.ok("修改成功");
    }
    @Log(module = "删除访客信息", operationType = 3, requestMethod = "DELETE")
    @ApiOperation("删除访客信息")
    @DeleteMapping("/visitor/{visitorId}")
    public ResponseResult<String> deleteVisitor(@PathVariable Long visitorId) {
        visitorService.removeById(visitorId);
        return ResponseResult.ok("删除成功");
    }
    @Log(module = "批量删除访客信息", operationType = 3, requestMethod = "DELETE")
    @ApiOperation("批量删除访客信息")
    @DeleteMapping("/visitors/{arr}")
    public ResponseResult<String> deleteVisitor(@PathVariable ArrayList<Long> arr) {
        visitorService.removeByIds(arr);
        return ResponseResult.ok("批量删除成功");
    }
    @Log(module = "添加访客邀请信息-小程序", operationType = 1, requestMethod = "POST")
    @PostMapping("/visitor")
    @ApiOperation("添加访客邀请信息-小程序")
    public ResponseResult<String> addVisitor(ZyVisitor visitor) {
        visitorService.save(visitor);
        return ResponseResult.ok("添加成功");
    }
}
